package main

import (
	"log"
	"net/http"

	"gitee.com/kouleen/job-admin/internal/middleware"
	"gitee.com/kouleen/job-admin/internal/routes"
	"github.com/gorilla/mux"
	"github.com/rs/cors"
)

func main() {
	r := mux.NewRouter()
	// 应用全局认证中间件
	authRouter := r.PathPrefix("/").Subrouter()
	c := cors.New(cors.Options{
		AllowedOrigins: []string{"*"}, // 允许所有域名，生产环境建议指定具体域名
		AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowedHeaders: []string{"Origin", "X-Requested-With", "Content-Type", "Accept", "Authorization", "token"},
	})
	authRouter.Use(middleware.AuthMiddleware())
	routes.SetUpPluginServerRoutes(authRouter)
	log.Printf("Server starting on port %s", "8071")
	log.Fatal(http.ListenAndServe(":"+"8071", c.Handler(r)))
}
